Program Organization Units
In addition to the IEC standard, you can write you own code as either a sub-program or UDFB.
Types |
IEC 61131-3 |
Written by end-user |
---|---|---|
Basic functions (has no memory) |
||
Instantiated functions (keep track of the past) |
Function Blocks (FB) |
User-Defined Function Blocks (UDFB) |
Differences between Functions and Function Blocks
- Functions are expected to complete in one cycle.
- Function Blocks can take several cycles to complete.
Description of FB Operation
Rather than halt the application or waiting for operations to complete, the FB typically gives control back to the application but does not set its Done output.
Examples of Operations Overrunning the Cycle Duration
- A motion command to move from one location to another can take several cycles to complete.
- Operations like reading/writing to files or reading and writing over TCP/IP can also take several cycles to complete.
Operation Sequence
- When an FB is called, it starts an operation and possibly does not complete it.
- The FB is called in the next cycle and it checks to determine if the operation is done.
- If it is done, it sets the Done output.
If not, it continues on. - Now the application knows that the operation is complete and can do what ever other processing it needs based on the FB being done.